~ chicken-core (chicken-5) /manual/Extensions to the standard


  1[[tags: manual]]
  2
  3[[toc:]]
  4
  5== Extensions to the R5RS standard
  6
  7=== Identifiers
  8
  9Identifiers may contain special characters if delimited with
 10{{| ... |}}.
 11
 12=== Brackets and braces
 13
 14The brackets {{[ ... ]}} and the braces {{ { ... } }} are
 15provided as an alternative syntax for {{( ... )}}.  A number of reader
 16extensions is provided. 
 17
 18=== Non-standard procedures and syntax
 19
 20CHICKEN provides numerous non-standard procedures. See the manual
 21sections on the included library modules ([[Included modules]]) for
 22more information.  Here we only document {{cond-expand}} because it is
 23always present in a module, even without imports.
 24
 25==== cond-expand
 26
 27<macro>(cond-expand FEATURE-CLAUSE ...)</macro>
 28
 29Expands by selecting feature clauses. This form is allowed to appear in non-toplevel expressions.
 30
 31Predefined feature-identifiers are "situation" specific:
 32
 33; compile : {{chicken}}, {{chicken-5}}, {{compiling}}, {{library}}, {{eval}}, {{extras}}, {{regex}}, {{srfi-0}}, {{srfi-2}}, {{srfi-4}}, {{srfi-6}}, {{srfi-8}}, {{srfi-9}}, {{srfi-10}}, {{srfi-11}}, {{srfi-12}}, {{srfi-15}}, {{srfi-16}}, {{srfi-17}}, {{srfi-23}}, {{srfi-26}}, {{srfi-28}}, {{srfi-30}}, {{srfi-31}}, {{srfi-39}}, {{srfi-55}}, {{srfi-61}}, {{srfi-62}}
 34
 35; load : {{chicken}}, {{chicken-5}}, {{extras}}, {{srfi-0}}, {{srfi-2}}, {{srfi-6}}, {{srfi-8}}, {{srfi-9}}, {{srfi-10}}, {{srfi-12}}, {{srfi-17}}, {{srfi-23}}, {{srfi-28}}, {{srfi-30}}, {{srfi-39}}, {{srfi-55}}, {{srfi-61}}, {{srfi-62}}. {{library}} is implicit.
 36
 37; eval : {{csi}}, {{chicken}}, {{chicken-5}}, {{extras}}, {{srfi-0}}, {{srfi-2}}, {{srfi-6}}, {{srfi-8}}, {{srfi-9}}, {{srfi-10}}, {{srfi-11}}, {{srfi-12}}, {{srfi-15}}, {{srfi-16}}, {{srfi-17}}, {{srfi-23}}, {{srfi-26}}, {{srfi-28}}, {{srfi-30}}, {{srfi-31}}, {{srfi-39}}, {{srfi-55}}, {{srfi-61}}, {{srfi-62}}. {{library}} is implicit.
 38
 39Also, features of the form {{chicken-5.X}}, where {{X}} denotes the minor version, are available.
 40
 41The symbols returned by the following procedures from [[Module (chicken platform)|(chicken platform)]] are also available as feature-identifiers in all situations: {{(machine-byte-order)}}, {{(machine-type)}}, {{(software-type)}}, {{(software-version)}}. For example, the {{machine-type}} class of feature-identifiers include {{arm}},
 42{{alpha}}, {{mips}}, etc.
 43
 44The [[Module (chicken platform)|(chicken platform)]] module also provides a function {{(features)}} that returns a list of all registered features.
 45
 46In addition the following feature-identifiers may exist: {{cross-chicken}}, {{dload}}, {{manyargs}}, {{ptables}}.
 47
 48For further information, see the documentation for
 49[[http://srfi.schemers.org/srfi-0/srfi-0.html|SRFI-0]].
 50
 51
 52=== User defined character names
 53
 54User defined character names are supported. See
 55{{char-name}}. Characters can be given
 56in hexadecimal notation using the ''#\xXX'' syntax where ''XX'' specifies the 
 57character code. Character codes above 255 are supported and can be read (and are
 58written) using the ''#\uXXXX'' and ''#\UXXXXXXXX'' notations.
 59
 60Non-standard characters names supported are {{#\tab}}, {{#\linefeed}}, {{#\return}}, {{#\alarm}},
 61{{#\vtab}}, {{#\nul}}, {{#\page}}, {{#\esc}}, {{#\delete}} and {{#\backspace}}.
 62
 63=== Special characters in strings
 64
 65CHICKEN supports special characters preceded with
 66a backslash ''\'' in quoted string
 67constants. ''\n'' denotes the newline-character,
 68''\r'' carriage return, ''\b''
 69backspace, ''\t'' TAB, ''\v'' vertical TAB, ''\a'' alarm, ''\f'' formfeed,
 70''\xXX'' a character with the code {{XX}} in hex and 
 71''\uXXXX'' (and ''\UXXXXXXXX'') a unicode character with the code {{XXXX}}.
 72The latter is encoded in UTF-8 format.
 73
 74== Non-standard read syntax
 75
 76=== Escapes in symbols
 77
 78{{| ... |}} may be used to escape a sequence of characters when reading a symbol.
 79{{\X}} escapes a single character in a symbols name:
 80
 81  (symbol->string '|abc def|)       =>   "abc def"
 82  (symbol->string '|abc||def|)      =>   "abcdef"
 83  (symbol->string '|abc|xyz|def|)   =>   "abcxyzdef"
 84  (symbol->string '|abc\|def|)      =>   "abc|def"
 85  (symbol->string 'abc\ def)        =>   "abc def"
 86
 87=== Multiline Block Comment
 88
 89<read>#|</read>
 90
 91 #| ... |# 
 92
 93A multiline ''block'' comment. May be nested. Implements [[http://srfi.schemers.org/srfi-30/srfi-30.html|SRFI-30]].
 94
 95=== Expression Comment
 96
 97<read>#;</read>
 98
 99 #;EXPRESSION
100
101Treats {{EXPRESSION}} as a comment.  That is, the comment runs through the whole S-expression, regardless of newlines, which saves you from having to comment out every line, or add a newline in the middle of your parens to make the commenting of the last line work, or other things like that. Implements [[http://srfi.schemers.org/srfi-62/srfi-62.html|SRFI-62]].
102
103=== External Representation
104
105<read>#,</read>
106
107 #,(CONSTRUCTORNAME DATUM ...)
108
109Allows user-defined extension of external representations. (For more information see the documentation for
110[[http://srfi.schemers.org/srfi-10/srfi-10.html|SRFI-10]])
111
112=== Location Expression
113
114<read> #$EXPRESSION</read>
115
116An abbreviation for {{(location EXPRESSION)}}.
117
118=== Blob literals
119
120<read>#${</read>
121
122  #${ HEX ... }
123
124Syntax for literal "blobs" (byte-sequences). Expects hexadecimal digits and ignores
125any whitespace characters:
126
127  #;1> ,d '#${deadbee f}
128  blob of size 4:
129     0: de ad be ef                                     ....
130
131=== Keyword
132
133<read>#:</read>
134
135 #:SYMBOL
136 SYMBOL:
137 :SYMBOL
138
139Syntax for keywords. Keywords are symbol-like objects that evaluate to themselves, and as such don't have to be quoted.  Either {{SYMBOL:}} or {{:SYMBOL}} is accepted, depending on the setting of the {{keyword-style}} parameter, but never both.  {{#:SYMBOL}} is always accepted.
140
141=== Multiline String Constant
142
143<read>#<<</read>
144
145 #<<TAG
146
147Specifies a multiline string constant. Anything up to a line equal to {{TAG}} (or end of file) will be returned as a single string:
148
149 (define msg #<<END
150  "Hello, world!", she said.
151 END
152 )
153
154is equivalent to
155
156 (define msg "\"Hello, world!\", she said.")
157
158=== Multiline String Constant with Embedded Expressions
159
160<read>#<#</read>
161
162 #<#TAG
163
164Similar to {{#<<}}, but allows substitution of embedded Scheme expressions prefixed with {{#}} and optionally enclosed in curly brackets. Two consecutive {{#}}s are translated to a single {{#}}:
165
166 (define three 3)
167 (display #<#EOF
168 This is a simple string with an embedded `##' character
169 and substituted expressions: (+ three 99) ==> #(+ three 99)
170 (three is "#{three}")
171 EOF
172 )
173
174prints
175
176 This is a simple string with an embedded `#' character
177 and substituted expressions: (+ three 99) ==> 102
178 (three is "3")
179
180=== Foreign Declare
181
182<read>#></read>
183
184 #> ... <#
185
186Abbreviation for {{(foreign-declare " ... ")}}.
187
188=== String escape sequences
189
190String-literals may contain the following escape sequences:
191
192<table style="margin-top: 1em; max-width: 40em">
193<tr><th>Escape sequence</th><th>Character</th></tr>
194<tr><td>{{\n}}</td><td>line feed / newline</td></tr>
195<tr><td>{{\t}}</td><td>tab</td></tr>
196<tr><td>{{\r}}</td><td>carriage return</td></tr>
197<tr><td>{{\b}}</td><td>backspace</td></tr>
198<tr><td>{{\a}}</td><td>bell</td></tr>
199<tr><td>{{\v}}</td><td>vertical tab</td></tr>
200<tr><td>{{\f}}</td><td>form feed</td></tr>
201<tr><td>{{\x}}''XX''</td><td>hexadecimal 8-bit character code</td></tr>
202<tr><td>{{\u}}''XXXX''</td><td>hexadecimal 16-bit Unicode character code</td></tr>
203<tr><td>{{\U}}''XXXXXXXX''</td><td>hexadecimal 32-bit Unicode character code</td></tr>
204<tr><td>{{\}}''OOO''</td><td>octal 8-bit character code</td></tr>
205<tr><td>{{\|}}   {{\"}}    {{\\}}    {{\'}}</td><td>the escaped character</td></tr>
206</table>
207
208
209=== Bang
210
211<read>#!</read>
212
213 #!... 
214
215Interpretation depends on the directly following characters. Only the following are recognized. Any other case results in a read error.
216
217; Line Comment : If followed by whitespace or a slash, then everything up the end of the current line is ignored
218
219; Eof Object : If followed by the character sequence {{eof}}, then the (self-evaluating) end-of-file object is returned
220
221; DSSSL Formal Parameter List Annotation : If followed by any of the character sequences {{optional}}, {{rest}} or {{key}}, then a symbol with the same name (and prefixed with {{#!}}) is returned
222
223; Read Mark Invocation : If a ''read mark'' with the same name as the token is registered, then its procedure is called and the result of the read-mark procedure will be returned
224
225=== Case Sensitive Expression
226
227<read>#cs</read>
228
229 #cs...
230
231Read the next expression in case-sensitive mode (regardless of the current global setting).
232
233=== Case Insensitive Expression
234
235<read>#ci</read>
236
237 #ci...
238
239Read the next expression in case-insensitive mode (regardless of the current global setting).
240
241=== Conditional Expansion
242
243<read>#+</read>
244
245 #+FEATURE EXPR
246
247Rewrites to
248
249 (cond-expand (FEATURE EXPR) (else))
250
251and performs the feature test at macroexpansion time.  Therefore, it may not
252work as expected when used within a macro form.
253
254---
255Previous: [[Deviations from the standard]]
256
257Next: [[Debugging]]
Trap